<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- qtquick-debugger-example.qdoc -->
  <title>Debugging a Qt Quick Example Application | Qt Creator Manual</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt Creator Manual</a></td><td >Debugging a Qt Quick Example Application</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="index.html">Qt Creator Manual 4.11.1</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
  <link rel="prev" href="creator-debugging-example.html" />
  <link rel="next" href="creator-troubleshooting-debugging.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="creator-debugging-example.html">Debugging a C++ Example Application</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="creator-troubleshooting-debugging.html">Troubleshooting Debugger</a>
</p><p/>
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Debugging a Qt Quick Example Application</h1>
<span class="subtitle"></span>
<!-- $$$creator-qml-debugging-example.html-description -->
<div class="descr"> <a name="details"></a>
<p>This section uses the <a href="http://doc.qt.io/qt-5/qml-advtutorial.html">Same Game</a> example application to illustrate how to debug Qt Quick applications in the <b>Debug</b> mode.</p>
<p>For more information about all the options you have, see <a href="creator-debugging-qml.html">Debugging Qt Quick Projects</a>.</p>
<p>The Same Game demo shows how to write a game in QML, using JavaScript for all the game logic. Open the demo project in Qt Creator to debug it:</p>
<ol class="1" type="1"><li>To look at the code that starts a new game, place a breakpoint in samegame.qml by clicking between the line number and the window border on the line where where the <code>startNewGame()</code> function is called (1).<p class="centerAlign"><img src="images/qtquick-example-setting-breakpoint1.png" alt="" /></p><p>The red circle indicates that a breakpoint is now set on that line number.</p>
</li>
<li>Select <b>Debug</b> &gt; <b>Start Debugging</b> &gt; <b>Start Debugging of Startup Project</b> or press <b>F5</b>.</li>
<li>Once the Same Game application starts, select <b>Puzzle</b> to start a new game.<p class="centerAlign"><img src="images/samegame.png" alt="" /></p></li>
<li>When the debugger hits the breakpoint, it interrupts the application. Qt Creator displays the nested function calls leading to the current position as a call stack trace (1).<p class="centerAlign"><img src="images/qtquick-example-setting-breakpoint2.png" alt="" /></p></li>
<li>Click the <img src="images/debugger_stepinto_small.png" alt="" /> (<b>Step Into</b>) button on the toolbar or press <b>F11</b> to step into the code in the stack. The samegame.js file opens in the code editor at the function that starts a new game.<p class="centerAlign"><img src="images/qtquick-example-stack.png" alt="" /></p></li>
<li>Examine the local variables in the <b>Locals</b> view. Step through the code to see how the information changes in the view.</li>
<li>Add a breakpoint at the end of the <code>startNewGame()</code> function, and click <img src="images/qtcreator-debugging-continue.png" alt="" /> (<b>Continue</b>) to hit the breakpoint.<p class="centerAlign"><img src="images/qtquick-example-setting-breakpoint3.png" alt="" /></p></li>
<li>To execute JavaScript commands in the current context, open the <b>QML Debugger Console</b> output pane.<p class="centerAlign"><img src="images/qml-script-console.png" alt="" /></p></li>
<li>To remove a breakpoint, right-click it and select <b>Delete Breakpoint</b>.</li>
<li>In the <b>Locals</b> view, explore the object structure at runtime.<p class="centerAlign"><img src="images/qtquick-example-qml-inspector.png" alt="" /></p></li>
<li>Select <b>Debug</b> &gt; <b>Show Application on Top</b> to keep the application visible while you interact with the debugger.</li>
<li>Select <b>Debug</b> &gt; <b>Select</b> to activate selection mode and then click the <b>Menu</b> button to move into the <b>menuButton</b> component in the <b>Locals</b> view and the code editor.</li>
<li>In the <b>Locals</b> view, double-click the value of a property to change it.</li>
</ol>
</div>
<!-- @@@creator-qml-debugging-example.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="creator-debugging-example.html">Debugging a C++ Example Application</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="creator-troubleshooting-debugging.html">Troubleshooting Debugger</a>
</p>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
